using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Rss;


namespace LWRSSReader
{
	public partial class Form1 : SkinableFormsLib.LWSkinableForm
	{


		
		private bool _isFull = true;
		private Form3 f3 = new Form3();
		public Settings Settings
		{
			get
			{
				return Program.Settings;
				

			}
		}

		public Form1()
		{
			InitializeComponent();
			lwListView1.Items.Clear();

			if (Settings != null)
			{
				Program.UpdateItemList(Settings.Feeds, lwListView1);
			}

			_isFull = !Settings.StartRolledUp;
			if (Settings.StartRolledUp)
			{
				this.BackgroundImage = global::LWRSSReader.Properties.Resources.header;
			}
			else
			{
				this.BackgroundImage = global::LWRSSReader.Properties.Resources.full;
			}
			
			
			
		}



		private void lwButton1_Click(object sender, EventArgs e)
		{
			if (!_isFull)
			{
				this.BackgroundImage = global::LWRSSReader.Properties.Resources.full;
				_isFull = true;

			}
			else
			{
				this.BackgroundImage = global::LWRSSReader.Properties.Resources.header;
				_isFull = false;


			}
		}

		private void lwButton2_Click(object sender, EventArgs e)
		{
			Program.UpdateItemList(Settings.Feeds, lwListView1);
		}

		private void lwButton3_Click(object sender, EventArgs e)
		{
			Form2 f2 = new Form2();
			if (f2.ShowDialog(this) == DialogResult.OK)
			{
				//show aggregated feeds
				Program.UpdateItemList(Settings.Feeds, lwListView1);
			}

		}


		private void lwButton5_Click(object sender, EventArgs e)
		{
			Close();
		}
		#region comment
		private void lwListView1_LWListViewScrollEvent(object o, SkinableFormsLib.LWListViewScrollEventArgs e)
		{

			/*ListViewHitTestInfo lvhti = null;
			ListViewItem lvi = null;
			lvhti = lwListView1.HitTest(5, Height / 2);
			if (lvhti.Item != null)
			{
				lvi = lvhti.Item;
			}

			if (lvi == null && lwListView1.Items.Count > 0)
			{
				lvi = lwListView1.Items[0];
			}


			if (lvi != null && lvi.Tag is RssItemInfoStruct)
			{
				RssItemInfoStruct rssItemInfoStruct = (RssItemInfoStruct)lvi.Tag;
				DisplayCurrentMedia(rssItemInfoStruct);
			}
			   */


		}
		#endregion


	







		private void lwListView1_SelectedIndexChanged(object sender, EventArgs e)
		{


			if (lwListView1.SelectedItems.Count > 0 && lwListView1.SelectedItems[0] != null && lwListView1.SelectedItems[0].Tag is RssItemInfoStruct)
			{
				RssItemInfoStruct rssItemInfoStruct = (RssItemInfoStruct)lwListView1.SelectedItems[0].Tag;
				Program.DisplayCurrentMedia(rssItemInfoStruct, true, lwPictureBox1, lwLinkLabel1);
			}

		}






		private void lwPictureBox1_MouseLeave(object sender, EventArgs e)
		{
			if (this.Focused && f3.Visible)
			{
				f3.Hide();
			}
		}

		private void lwPictureBox1_LoadProgressChanged(object sender, ProgressChangedEventArgs e)
		{
			if (e.ProgressPercentage == 100)
			{
				lwPictureBox1.Visible = true;

			}
			else
			{
			}


		}


		private void lwPictureBox1_Click(object sender, EventArgs e)
		{
			if (lwPictureBox1.IsImageBigger)
			{
				f3.BackgroundImage = lwPictureBox1.Image;
				f3.Size = lwPictureBox1.Image.Size;

				f3.ShowDialog(this);
			}
		}

		


		private void Form1_Load(object sender, EventArgs e)
		{
			
			toolTip1.SetToolTip(lwButton1, "Roll up/down");
			toolTip1.SetToolTip(lwButton2, "Reload feeds");
			toolTip1.SetToolTip(lwButton3, "Settings");
			toolTip1.SetToolTip(lwButton5, "Close");
			toolTip1.SetToolTip(lwButton4, "Switch UI");


		}

		private void lwLinkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
		{

			try
			{
				System.Diagnostics.Process.Start(((Uri)e.Link.LinkData).AbsoluteUri);
			}
			catch
			{
			}
		}

		private void lwPictureBox1_LoadCompleted(object sender, AsyncCompletedEventArgs e)
		{
			if (lwPictureBox1.Image == lwPictureBox1.ErrorImage)
			{
				lwPictureBox1.Image = lwPictureBox1.InitialImage;
			}
			
		}

		private void lwButton4_Click(object sender, EventArgs e)
		{
			Program.SwitchUI();
		}






	}


}